package com.yupi.oj.model.dto.question;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.yupi.oj.model.entity.Question;
import com.yupi.oj.model.vo.QuestionVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 题目创建请求
 */
@Data
@ApiModel("题目创建请求")
public class QuestionAddRequest implements Serializable {

    @ApiModelProperty(value = "题目标题")
    private String title;

    @ApiModelProperty(value = "题目描述")
    private String description;

    @ApiModelProperty(value = "输入")
    private String input;

    @ApiModelProperty(value = "输出")
    private String output;

    @ApiModelProperty(value = "样例")
    private List<ExampleDTO> exampleDTOList;

    @ApiModelProperty(value = "提示")
    private String tip;

    @ApiModelProperty(value = "难度等级")
    private String difficultLevel;

    @ApiModelProperty(value = "标签（数组）")
    private List<String> tagList;

    @ApiModelProperty(value = "内存限制（KB）")
    private Integer memoryLimit;

    @ApiModelProperty(value = "时间限制（ms）")
    private Integer timeLimit;

    private static final long serialVersionUID = 1L;


    /**
     * pojo to bean
     */
    public static Question pojoToBean(QuestionAddRequest questionAddRequest) {
        List<ExampleDTO> exampleDTOList = questionAddRequest.getExampleDTOList();
        List<String> tagList = questionAddRequest.getTagList();
        Question question = new Question();
        BeanUtils.copyProperties(questionAddRequest, question);

        if (ObjectUtil.isNotEmpty(exampleDTOList)) {
            question.setExample(JSONUtil.toJsonStr(exampleDTOList));
        }
        if (ObjectUtil.isNotEmpty(tagList)) {
            question.setTag(JSONUtil.toJsonStr(tagList));
        }
        return question;
    }

}